#ifndef HTMLEDIT_H
#define HTMLEDIT_H

#include <QWidget>
//#include <QTextCursor>
#include <Qt>
#include <QTextDocument>

namespace Ui {
	class HtmlEdit;
}

class HtmlEdit : public QWidget
{
		Q_OBJECT
		Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)


		const static QString DefaultImageResourceName; //will be removed after migration to QTextDocument

	private: //classes

		struct FocusCapturer; //auxiliary class used not to lose focus while dialogs are open from the widget

	public:

		explicit HtmlEdit(QWidget *parent = 0);
		~HtmlEdit();

		QString imageResourceName() const;
		void setImageResourceName(const QString& value);

		QTextDocument* document() const;

		bool isReadOnly() const;
		bool isEditMode() const;

		void enterEditMode();
		void exitEditMode();

		Qt::AlignmentFlag horizontalAlignment() const;

		void setImageResource(QImage image);

		void clear();
		void setHorizontalAlignment(Qt::AlignmentFlag);
		void setImageResource(QString resourceName, QImage image);
		void setHtml(QString html);

		void addAction(QAction *action); //shortcuts did not work without it. More elegant solution is required

		bool eventFilter(QObject * target, QEvent * evt);

	public slots:

		void setDocument(QTextDocument* value);
		void setReadOnly(bool value);
		void setContentIsVisible(bool value);

	signals:

		void readOnlyChanged(bool value);
		void focusOut();

		void editModeExited();

	private slots:

		void slot_addImage();

	private:

		void toReadOnlyMode();
		void toEditMode();

	private:

		QString m_imageResourceName;
		Ui::HtmlEdit *ui;
		QTextDocument* m_pDocument;
		bool m_isReadOnly;
		Qt::AlignmentFlag m_horizontalAlignment; //horizontal alignment
		bool m_focusIsCaptured; //auxiliary flag used not to lose focus while dialogs are called from the widget
};

#endif // HTMLEDIT_H
